﻿using DotNetExtensions.Core.Converters;
using DotNetExtensions.Core.Helpers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;

namespace CoreSimple
{
    public class TypeSimple
    {
        public static void Parse()
        {
            string json = "{\"data\":{\"total\":15,\"pages\":1,\"pageSize\":20,\"pageIndex\":1,\"isEmpty\":false,\"data\":[{\"id\":\"1000703050000121\",\"code\":\"L007\",\"name\":\"米\",\"isBase\":true,\"baseUOM\":\"1000703050000121\",\"round\":5.0,\"ratioToBase\":1.000000000,\"description\":null},{\"id\":\"1000703050000125\",\"code\":\"L006\",\"name\":\"千米\",\"isBase\":false,\"baseUOM\":\"1000703050000121\",\"round\":5.0,\"ratioToBase\":1000.000000000,\"description\":null},{\"id\":\"1000703050000126\",\"code\":\"Hour\",\"name\":\"小时\",\"isBase\":false,\"baseUOM\":\"1000703080000001\",\"round\":5.0,\"ratioToBase\":60.000000000,\"description\":null},{\"id\":\"1000703050000129\",\"code\":\"Day\",\"name\":\"天\",\"isBase\":false,\"baseUOM\":\"1000703050000126\",\"round\":5.0,\"ratioToBase\":24.000000000,\"description\":null},{\"id\":\"1000703050000130\",\"code\":\"W013\",\"name\":\"公斤\",\"isBase\":true,\"baseUOM\":\"1000703050000130\",\"round\":5.0,\"ratioToBase\":1.000000000,\"description\":null},{\"id\":\"1000703050000131\",\"code\":\"W014\",\"name\":\"斤\",\"isBase\":false,\"baseUOM\":\"1000703050000130\",\"round\":5.0,\"ratioToBase\":0.500000000,\"description\":null},{\"id\":\"1000703050000133\",\"code\":\"W015\",\"name\":\"吨\",\"isBase\":false,\"baseUOM\":\"1000703050000130\",\"round\":5.0,\"ratioToBase\":1000.000000000,\"description\":null},{\"id\":\"1000703050000136\",\"code\":\"A020\",\"name\":\"平方米\",\"isBase\":true,\"baseUOM\":\"1000703050000136\",\"round\":5.0,\"ratioToBase\":1.000000000,\"description\":null},{\"id\":\"1000703050000137\",\"code\":\"A021\",\"name\":\"平方分米\",\"isBase\":false,\"baseUOM\":\"1000703050000136\",\"round\":5.0,\"ratioToBase\":0.010000000,\"description\":null},{\"id\":\"1000703050000138\",\"code\":\"B030\",\"name\":\"立方米\",\"isBase\":true,\"baseUOM\":\"1000703050000138\",\"round\":5.0,\"ratioToBase\":1.000000000,\"description\":null},{\"id\":\"1000703050000139\",\"code\":\"B031\",\"name\":\"立方分米\",\"isBase\":false,\"baseUOM\":\"1000703050000138\",\"round\":5.0,\"ratioToBase\":0.001000000,\"description\":null},{\"id\":\"1000703050000140\",\"code\":\"F040\",\"name\":\"个\",\"isBase\":true,\"baseUOM\":\"1000703050000140\",\"round\":5.0,\"ratioToBase\":1.000000000,\"description\":null},{\"id\":\"1000703080000001\",\"code\":\"Minute\",\"name\":\"分\",\"isBase\":false,\"baseUOM\":\"1000703080000002\",\"round\":5.0,\"ratioToBase\":60.000000000,\"description\":null},{\"id\":\"1000703080000002\",\"code\":\"Second\",\"name\":\"秒\",\"isBase\":true,\"baseUOM\":\"1000703080000002\",\"round\":0.0,\"ratioToBase\":1.000000000,\"description\":null},{\"id\":\"1002212190005644\",\"code\":\"PCS\",\"name\":\"PCS\",\"isBase\":true,\"baseUOM\":\"1002212190005644\",\"round\":0.0,\"ratioToBase\":1.000000000,\"description\":null}]},\"code\":200,\"msg\":\"The operation was executed successfully\"}";
            DotNetExtensions.Core.Helpers.TypePropertyParser parser = new DotNetExtensions.Core.Helpers.TypePropertyParser();

            List<TypePropertyTree> items = parser.Parse(json);
            List<TypePropertyItem> lines = parser.ToList(items);
            foreach (var item in lines)
            {
                Console.WriteLine(JsonConvert.SerializeObject(item));
            }
            Console.WriteLine(lines);
        }
    }

    public class Root
    {
        public int Id { get; set; }
        public int Age { get; set; }
        public string Name { get; set; }
        public DateTime Birth { get; set; }
        public long Times { get { return DateTimeConvert.GetTimestamp(Birth); } }

        public List<Hobi> Hobis { get; set; }

        public Position Pos { get; set; }
    }

    public class Hobi
    {
        public string Name { get; set; }
        public string Remark { get; set; }
        public int Year { get; set; }
        public DateTime Begin { get; set; }
    }

    public class Position
    {
        public string Country { get; set; }
        public string City { get; set; }
        public string Street { get; set; }
    }
}
